import { formatDate } from "@/filter/index";

export const testData = [];
// 生成随机数
function leftOpen(n, m) {
  var result = Math.random() * (m - n + 1) + n - 1;
  while (result < n) {
    result = Math.random() * (m - n + 1) + n - 1;
  }
  return Number(result.toFixed(3));
}
// 生成测试数据
export var start = new Date("2022-12-12T11:00:00"); // 设置开始时间
export var end = new Date("2022-12-12T14:11:00"); // 设置结束时间
var chaochu_1 = new Date("2022-12-12T13:00:00"); // 设置开始时间
var chaochu_2 = new Date("2022-12-12T13:05:00"); // 设置开始时间
var timeArray = []; // 创建空的时间数组
export const renderTestArr = () => {
  let meter1RunStageNO = 1; //阶段
  let meter1RealTemp = 300;
  let meter2RealTemp = 300;
  let meter3RealTemp = 300;
  function renderTime() {
    if (start > end) {
      return;
    }

    // 到五百的时候 开始保温
    if (
      meter1RealTemp >= 800 ||
      meter2RealTemp >= 800 ||
      meter3RealTemp >= 800
    ) {
      meter1RunStageNO = 2;
      meter1RealTemp = leftOpen(800.5, 802.9);
      meter2RealTemp = leftOpen(800.5, 805.12);
      meter3RealTemp = leftOpen(800.5, 803.53);
    } else {
      meter1RealTemp += leftOpen(1.58, 2.97);
      meter2RealTemp += leftOpen(1.78, 2.77);
      meter3RealTemp += leftOpen(1.98, 2.57);
    }
    if (chaochu_1 < start && chaochu_2 > start) {
      meter1RealTemp = leftOpen(811.5, 811.9);
    }

    // 将当前时间添加到时间数组中
    timeArray.push({
      eventDate: formatDate(start),
      metadata: {
        meter1RealTemp,
        meter2RealTemp,
        meter3RealTemp,
        meter1RunStageNO
      }
    });
    // 增加三十秒
    start.setSeconds(start.getSeconds() + 30);
    renderTime();
  }
  renderTime();
  console.log("timeArray() :>> ", timeArray);
  return timeArray;
};
